package com.example.tool.activtiy.recylerview;

import android.support.design.widget.AppBarLayout;
import android.support.v7.widget.AppCompatCheckBox;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.entity.MultiItemEntity;
import com.example.tool.R;
import com.example.tool.activtiy.base.BaseActivity;
import com.example.tool.adapter.ExpandAdapter;
import com.example.tool.adapter.base.decoration.RecycleViewDivider;
import com.example.tool.bean.RexueDetail;
import com.example.tool.bean.RexueJobBean;
import com.example.tool.bean.RexueWeapon;
import com.example.tool.mvp.CommonPresent;
import com.gyf.immersionbar.BarHide;
import com.gyf.immersionbar.ImmersionBar;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import butterknife.BindView;

/**
 * Created Date 2019/8/25.
 *
 * @author liangkun
 * ClassDescription：层级条目
 */
public class ExpandItemRvActivity extends BaseActivity<CommonPresent> {
    @BindView(R.id.rv_expand)
    protected RecyclerView rvExpand;
    @BindView(R.id.cbOnlyExpandOne)
    protected AppCompatCheckBox checkBox;
    @BindView(R.id.tv_title)
    protected TextView tvTitle;
    @BindView(R.id.toolbarRightIcon)
    protected ImageView ivMore;
    @BindView(R.id.appbar)
    protected AppBarLayout barLayout;
    private ExpandAdapter expandAdapter;
    private LinearLayoutManager linearLayoutManager;
    private List<MultiItemEntity> list;

    @Override
    protected int getLayoutId() {
        return R.layout.activtiy_expand_rv;
    }

    @Override
    protected void initView() {


        ImmersionBar.with(this)
                .transparentStatusBar()  //透明状态栏，不写默认透明色
                .transparentNavigationBar()//透明导航栏，不写默认黑色(设置此方法，fullScreen()方法自动为true)
                .statusBarColor(R.color.color_white)
                .fitsSystemWindows(true)
                .statusBarDarkFont(true)   //状态栏字体是深色，不写默认为亮色
                .navigationBarColor(R.color.color_e2dfdd) //导航栏颜色，不写默认黑色
//                .navigationBarDarkIcon(true)//导航栏图标是深色，不写默认为亮色;
                .hideBar(BarHide.FLAG_HIDE_NAVIGATION_BAR)  //隐藏状态栏或导航栏或两者，不写默认不隐藏
                .init();

        tvTitle.setText("Expandview");
        ivMore.setVisibility(View.VISIBLE);
        ivMore.setImageResource(R.mipmap.iv_bar_more);
        linearLayoutManager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
        rvExpand.addItemDecoration(new RecycleViewDivider(this, LinearLayoutManager.VERTICAL,
                getResources().getDimensionPixelOffset(R.dimen.sw_dp_15), 0, 0, getResources().getColor(R.color.color_white)));
        rvExpand.setLayoutManager(linearLayoutManager);
        list = generateData();
        expandAdapter = new ExpandAdapter(generateData());

//        final GridLayoutManager manager = new GridLayoutManager(this, 3);
//        manager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
//            @Override
//            public int getSpanSize(int position) {
//                return expandAdapter.getItemViewType(position) == ConstantVale.REXUE_PERSON ? 1 : manager.getSpanCount();
//            }
//        });
//
//        rvExpand.setLayoutManager(manager);
        rvExpand.setAdapter(expandAdapter);

    }

    private List<MultiItemEntity> generateData() {
        int lv1Count = 3;
        int personCount = 3;

        String[] nameList = {"热血江湖-刀", "热血江湖-枪", "热血江湖-剑", "热血江湖-医", "热血江湖-弓"};
        Random random = new Random();

        ArrayList<MultiItemEntity> res = new ArrayList<>();
        for (int i = 0; i < nameList.length; i++) {
            RexueJobBean rexueJobBean = new RexueJobBean(nameList[i]);
            for (int j = 0; j < lv1Count; j++) {
                RexueWeapon rexueWeapon = new RexueWeapon((j+1) + "转武器");
                for (int k = 0; k < personCount; k++) {
                    if (nameList[i].equals("热血江湖-刀")) {
                        if (k == 0) {
                            rexueWeapon.addSubItem(new RexueDetail("闪电刀"));
                        } else if (k == 1) {
                            rexueWeapon.addSubItem(new RexueDetail("青龙刀"));
                        } else if (k == 2) {
                            rexueWeapon.addSubItem(new RexueDetail("深渊刀"));
                        }
                    } else if (nameList[i].equals("热血江湖-枪")) {
                        if (k == 0) {
                            rexueWeapon.addSubItem(new RexueDetail("月影枪"));
                        } else if (k == 1) {
                            rexueWeapon.addSubItem(new RexueDetail("七星枪"));
                        } else {
                            rexueWeapon.addSubItem(new RexueDetail("益宣枪"));
                        }
                    } else if (nameList[i].equals("热血江湖-剑")) {
                        if (k == 0) {
                            rexueWeapon.addSubItem(new RexueDetail("血锋剑"));
                        } else if (k == 1) {
                            rexueWeapon.addSubItem(new RexueDetail("血锋剑"));
                        } else {
                            rexueWeapon.addSubItem(new RexueDetail("青魄剑"));
                        }
                    } else if (nameList[i].equals("热血江湖-医")) {
                        if (k == 0) {
                            rexueWeapon.addSubItem(new RexueDetail("雁离杖"));
                        } else if (k == 1) {
                            rexueWeapon.addSubItem(new RexueDetail("火欲杖"));
                        } else {
                            rexueWeapon.addSubItem(new RexueDetail("龙骨杖"));
                        }
                    } else {
                        if (k == 0) {
                            rexueWeapon.addSubItem(new RexueDetail("神谕弓"));
                        } else if (k == 1) {
                            rexueWeapon.addSubItem(new RexueDetail("圣者弓"));
                        } else {
                            rexueWeapon.addSubItem(new RexueDetail("神臂弓"));
                        }
                    }

                }
                rexueJobBean.addSubItem(rexueWeapon);
            }
            res.add(rexueJobBean);
        }

        return res;
    }


    @Override
    protected void initData() {

    }

    @Override
    protected void initEvent() {
        checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                expandAdapter.setOnlyExpandOne(isChecked);
            }
        });
    }

    @Override
    protected CommonPresent createPresenter() {
        return null;
    }
}